'use strict';

const Controller = require('egg').Controller;

class VoteController extends Controller {
    async createvote() { //添加
        const { ctx } = this;
        const { title,
            info,
            add,
            chooseList,
            isSingle, //单选
            anonymity, //匿名
            date } = ctx.request.body;
        let res = await ctx.service.vote.add(ctx.request.body);
        if (res.affectedRows == 1) {
            ctx.body = {
                code: 0,
                mes: '添加成功'
            }
        } else {
            ctx.body = {
                code: 1,
                mes: '添加失败'
            }
        }
    }
    async list(){
        const {ctx}  = this;
        const {userId} = ctx.query
        try{
            let res = await ctx.service.vote.getlist({userId});
            ctx.body = {
                code:0,
                data:res,
                mes:'成功'
            };
        }catch(e){
            ctx.body = {
                code:1,
                mes:'获取数据失败'
            }
        } 
    }


}

module.exports = VoteController;
